<script setup>
import my_head from '../../components/head.vue'
import 'bootstrap-icons/font/bootstrap-icons.min.css'
import { ref } from 'vue'

// 模拟数据

const products = [
  { id: 1, name: '产品 A', description: '高性能产品', flag: "tool1" },
  { id: 2, name: '产品 B', description: '优质产品', flag: "tool1" },
  { id: 3, name: '产品 C', description: '创新产品', flag: "tool1" },
  { id: 4, name: '产品 D', description: '热销产品', flag: "tool1" },
  { id: 5, name: '产品 E', description: '精品产品', flag: "tool1" },
  { id: 6, name: '产品 F', description: '特色产品', flag: "tool1" },
  { id: 7, name: '产品 G', description: '新品推荐', flag: "tool1" },
  { id: 8, name: '产品 H', description: '经典产品', flag: "tool1" },
  { id: 8, name: '产品 H', description: '经典产品', flag: "tool1" },
  { id: 8, name: '产品 H', description: '经典产品', flag: "tool1" },
  { id: 8, name: '产品 H', description: '经典产品', flag: "tool1" }
];


const product_n = ref(products)
const input_item = ref('0')

const totop = () => {
  window.scrollTo(0, 0);
}

const fenlei = (n) => {
  const newArr = products.filter(item => item['id'] % n == 0);
  product_n.value = newArr
}

const search_n = () => {
  const newArr = products.filter(item => item['id'] == input_item.value);
  if (newArr.length > 0) product_n.value = newArr
}
</script>

<template>
  <div class="container text-center">
    <my_head></my_head>

    <div class="row classify">
      <div class="col">
        <div class="row align-items-center">
          <div class="col-auto text-primary-hover" @click="fenlei(1)">
            全部
          </div>
          <div class="col-auto text-primary-hover" @click="fenlei(2)">
            类一
          </div>
          <div class="col-auto text-primary-hover" @click="fenlei(3)">
            类二
          </div>
          <div class="col-auto ms-auto me-auto" >
            <div class="input-group" style="max-width: 500px;">
              <!-- 输入框 -->
              <input type="text" class="form-control" placeholder="搜索内容..." aria-label="搜索内容"
                aria-describedby="search-btn" v-model="input_item">
              <!-- 搜索按钮 -->
              <button class="btn btn-primary" type="button" id="search-btn" @click="search_n">
                <i class="bi bi-search"></i> 搜索
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="row tool">
      <div class="col-sm-6 col-md-4 col-lg-3" v-for="i in product_n">
        <div>
          <a href=""><img style="width: 96%;" src="../../assets/bongocat.png" /></a>
          <div>
            <a class="link-underline link-primary link-underline-opacity-0 link-underline-opacity-0-hover"
              :href="i['flag'] + '.html'">
              abc
              <br>
              <small>
                {{ i['name'] }}
              </small>
            </a>
          </div>
          <p>介绍</p>
        </div>
      </div>
    </div>
  </div>
  <div class="sticky-bottom">
    <i class="bi bi-arrow-up-circle" @click="totop"></i>
  </div>

</template>

<style scoped>
.sticky-bottom {
  bottom: 100px;
  display: flex;
  justify-content: flex-end;
  padding-right: 50px;
}

.sticky-bottom i {
  font-size: 2rem;
  color: cornflowerblue;
  cursor: pointer;
  transition: all 0.3s ease;
}

.sticky-bottom i:hover {
  color: #4169e1; /* 更深的cornflowerblue */
  transform: scale(1.1);
}

.classify .row {
  margin: 0;
  background-color: white;
  padding: 1rem 0;
  margin-bottom: 3rem;
  border-radius: 5px;
}

.classify .col-auto {
  cursor: pointer;
}

.text-primary-hover:hover {
  color: #0d6efd !important;
}

.tool>div>div {
  background-color: white;
  border-radius: 5px;
}

.tool img {
  margin-top: 0.3rem;
}

.tool .link-underline small {
  color: grey;
}

.tool .link-underline:hover {
  font-weight: bold;
}


@media (max-width: 575.98px) {
  .tool>div>div {
    max-width: 300px;
    margin: 0 auto;
  }
}

.title {
  text-align: start;
}

.title h2 {
  margin: 1rem;
  margin-left: 0;
  color: white;
}
</style>
